package es.udc.pfc.davidparedes.model.unavailable;

import java.util.Calendar;
import java.util.List;

import org.springframework.stereotype.Repository;

import es.udc.pfc.davidparedes.model.dao.GenericDaoHibernate;

@Repository("unavailableDao")
public class UnavailableDaoHibernate extends
		GenericDaoHibernate<Unavailable, Long> implements UnavailableDao {
	
	@SuppressWarnings("unchecked")
	public List<Unavailable> findUnavailablesByDate(Long userProfileId, Calendar startDate, Calendar endDate) {
		return getSession()
				  .createQuery(
				  "SELECT u FROM Unavailable u WHERE "
				  + "u.vendor.userProfileId = :userProfileId AND "
				  + "u.start >= :startDate AND u.end <= :endDate ORDER BY u.start")
				  .setParameter("userProfileId", userProfileId)
				  .setCalendarDate("startDate", startDate)
				  .setCalendarDate("endDate", endDate)
				  .list();
	}

}
